package org.yzh.protocol.body;

import io.netty.buffer.ByteBuf;

public class Engine {

    public static final int id = 0x01;

    public static int id() {
        return id;
    }

    private int state;
    private int speed;
    private int fuelConsumptionRate;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getFuelConsumptionRate() {
        return fuelConsumptionRate;
    }

    public void setFuelConsumptionRate(int fuelConsumptionRate) {
        this.fuelConsumptionRate = fuelConsumptionRate;
    }

    public static class Schema implements io.github.yezhihao.protostar.Schema<Engine> {

        public static final Schema INSTANCE = new Schema();

        private Schema() {
        }

        @Override
        public Engine readFrom(ByteBuf input) {
            Engine message = new Engine();
            message.state = input.readUnsignedByte();
            message.speed = input.readUnsignedShort();
            message.fuelConsumptionRate = input.readUnsignedShort();
            return message;
        }

        @Override
        public void writeTo(ByteBuf output, Engine message) {
            output.writeByte(message.state);
            output.writeShort(message.speed);
            output.writeShort(message.fuelConsumptionRate);
        }
    }
}